# -*- coding: utf-8 -*-
from django.shortcuts import render
from django.http import HttpResponse

#引入自己创建端表单类
from .forms import AddForm
# Create your views here.

__author__ = 'Lemon Cheng'

def index(request):
    if request.method =='POST': #当提交表单时
        form = AddForm(request.POST) #form 包含提交当数据
        if form.is_valid():
            a = form.cleaned_data['a']
            b = form.cleaned_data['b']
            return HttpResponse(str(int(a)+int(b)))
    else:
        form = AddForm()
    return render(request,'index.html',{'form':form})

def add(request):
    a = request.GET['a']
    b = request.GET['b']
    c = int(a) + int(b)
    return HttpResponse(str(c))


def add2(request,a,b):
    c = int(a) + int(b)
    return HttpResponse(str(c))